﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[proc_Assets_Update_Diaobo] 
	(

	@checks VARCHAR(1000),
	@userid VARCHAR(30),	
	@username_1 NVARCHAR(50),
	@companyid int,
	@companyname nvarchar(200)
	)
AS
BEGIN
DECLARE @cSql NVARCHAR(4000)

set @cSql='
	INSERT INTO [zcjl]([zcbh] ,[memo] ,[lrrq] ,[userid] ,[username])
	SELECT anumber,	
    ''该资产原使用人''+ename + ''(''+username+ '')，于'+Convert(varchar(10),getdate(),120)+'释放该资产并调拨到'+@companyname+'。'',
		getdate(), '''+@userid+''' , '''+@username_1+'''  FROM Assets WHERE  id IN ('+ @checks +')
	
	
	update assets set departmentid=0,username='''',ename='''',stateid=2,companyid='+convert(varchar,@companyid)+' where id in ('+@checks+') 
	'
	--	update assets set departmentid=0,username='''',ename='''',stateid=2,companyid='+convert(varchar,@companyid)+' where id in ('+@checks+') 

	--print(@cSql)
	exec(@cSql)
	
END


